import React,{Component} from "react";
import {connect} from 'react-redux';
import {setSelectedKey} from "../../actions";
import ContainerItem from '../../components/ContainerItem/ContainerItem';
import TableItem from '../../components/TableItem/TableItem';

class RoleList extends Component{
    constructor(props){
        super(props);
        this.state={};
    }

    render() {
        const btnList=[
            {
                label:'新增',
                icon:'plus',
                type:'primary',
                handleOnClick:this.handleAdd
            }
        ];
        const dataSource = [
            {
                key: '1',
                name: '胡彦斌',
                age: 32,
                address: '西湖区湖底公园1号',
            },
            {
                key: '2',
                name: '胡彦祖',
                age: 42,
                address: '西湖区湖底公园1号',
            },
        ];

        const columns = [
            {
                title: '姓名',
                dataIndex: 'name',
                key: 'name',
            },
            {
                title: '年龄',
                dataIndex: 'age',
                key: 'age',
            },
            {
                title: '住址',
                dataIndex: 'address',
                key: 'address',
            },
        ];
        const pagination={
            total:25,
            pageSize:10,
            current:1,
            showSizeChanger:true,
            showQuickJumper:true
        };
        const tableSetting={
            dataSource,
            columns,
            minWidth:"900px",
            pagination:false
        };
        return(
            <div>
                <ContainerItem title={"角色列表"}>
                    <TableItem btnList={btnList} tableSetting={tableSetting} />
                </ContainerItem>
            </div>
        )
    }

    componentDidMount() {
        this.props.setSelectedKey('/index/roleList');
    }

    /**
     * 处理跳转新增角色页面事件
     */
    handleAdd=()=>{
        this.props.history.push('/index/roleAdd');
    }
}

const mapStateToProps=state=>{
    return{
        selectedKey:state.setSelectedKey
    }
};

const mapDispatchToProps=(dispatch)=>{
    return{
        setSelectedKey:selectedKey=>{
            dispatch(setSelectedKey(selectedKey))
        }
    }
};

export default connect(mapStateToProps,mapDispatchToProps)(RoleList);
